[java] How to get a reversed list view on a list in Java?

您所在的位置:网站首页 idea classnotfound [java] How to get a reversed list view on a list in Java?

[java] How to get a reversed list view on a list in Java?

#[java] How to get a reversed list view on a list in Java?| 来源: 网络整理| 查看: 265

Use the .clone() method on your List. It will return a shallow copy, meaning that it will contain pointers to the same objects, so you won't have to copy the list. Then just use Collections.

Ergo,

Collections.reverse(list.clone());

If you are using a List and don't have access to clone() you can use subList():

List shallowCopy = list.subList(0, list.size()); Collections.reverse(shallowCopy);


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3